package com.hsxxherp.ation.common.utils.json;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Objects;

public class AtionGsonBuilder {
    private static final GsonBuilder INSTANCE = new GsonBuilder();

    private static volatile Gson GSON_INSTANCE;

    static {
        // 驼峰
        INSTANCE.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);

        // 处理处理器
        INSTANCE.registerTypeAdapter(String.class, new StringAdapter());
    }

    /**
     * 构建GSON
     *
     * @return
     */
    public static Gson create() {
        if (Objects.isNull(GSON_INSTANCE)) {
            synchronized (INSTANCE) {
                if (Objects.isNull(GSON_INSTANCE)) {
                    GSON_INSTANCE = INSTANCE.serializeNulls().create();
                }
            }
        }
        return GSON_INSTANCE;
    }
}
